//
//  YGItemsCollectionViewCell.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/3/28.
//

#import "YGItemsCollectionViewCell.h"
#import "YGProductItemModel.h"
@interface YGItemsCollectionViewCell ()
@property (nonatomic, strong) UIImageView *coverImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) YGProductItemModel *model;

@end
@implementation YGItemsCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initContaints];
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 10;
        self.clipsToBounds = YES;
    }
    return self;
}

- (void)initView{
    [self addSubview:self.coverImageView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.priceLabel];
}


- (void)initContaints{
    [self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(self);
        make.height.mas_equalTo(self.mas_width);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.coverImageView.mas_bottom).offset(0);
        make.left.right.mas_equalTo(10);
        make.height.mas_equalTo(30);
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(0);
        make.left.right.mas_equalTo(10);
        make.height.mas_equalTo(20);

    }];
}

- (void)configureData:(id)data{
    self.model = data;
    [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:self.model.thumbnail] placeholderImage:nil];
    self.titleLabel.text = self.model.name;
    self.priceLabel.text = [@(self.model.price) stringValue];
}


- (UILabel *)priceLabel{
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textColor = UIColorFromRGB(0xE55667);
        _priceLabel.font = [UIFont systemFontOfSize:10];
    }
    return _priceLabel;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = UIColorFromRGB(0x000000);
        _titleLabel.font = [UIFont systemFontOfSize:12];
    }
    return _titleLabel;
}

- (UIImageView *)coverImageView{
    if (!_coverImageView) {
        _coverImageView = [[UIImageView alloc] init];
        _coverImageView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _coverImageView;
}
@end
